from peewee import *
import json
import  os

from orm.RetryOperationalError import RetryMySQLDatabase
with open(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '/config/mysql.json', 'r',
          encoding='utf8')as fp:
    json_data = json.load(fp)
    # db = pymysql.connect(json_data["url"], json_data["user"], json_data["pwd"], json_data["database"])
database = RetryMySQLDatabase(json_data["database"],
                                 **{'charset': 'utf8', 'use_unicode': True, 'host': json_data["url"],
                            'port': int(json_data["port"]), 'user': json_data["user"],
                            'password': json_data["pwd"]})
class UnknownField(object):
    def __init__(self, *_, **__): pass

class BaseModel(Model):
    class Meta:
        database = database

class TGpSssj(BaseModel):
    amount = CharField(null=True)
    buy = CharField(null=True)
    changepercent = CharField(null=True)
    code = CharField(null=True)
    high = CharField(null=True)
    low = CharField(null=True)
    mktcap = CharField(null=True)
    name = CharField(null=True)
    nmc = CharField(null=True)
    open = CharField(null=True)
    pb = CharField(null=True)
    per = CharField(null=True)
    pricechange = CharField(null=True)
    sell = CharField(null=True)
    settlement = CharField(null=True)
    symbol = CharField(null=True)
    ticktime = CharField(null=True)
    trade = CharField(null=True)
    turnoverratio = CharField(null=True)
    volume = CharField(null=True)

    class Meta:
        table_name = 't_gp_sssj'
        primary_key = False

